home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
3_0
/
DOUBLEDE
/
DEMOSTUF.C
< prev
next >
Wrap
C/C++ Source or Header
|
1988-07-28
|
3KB
|
156 lines
#include "shell.h"
posbutton(which)
int which;
{
Rect r;
r = windows[which]->portRect;
r.right -= SCROLLBARWIDTH;
r.bottom -= 30;
r.top = r.bottom -20;
InsetRect(&r,(r.right-r.left-80)/2,0);
HideControl(demoButton[which]);
MoveControl(demoButton[which],r.left,r.top);
SizeControl(demoButton[which],80,20);
ShowControl(demoButton[which]);
}
do_demo(which)
int which;
{
DialogTHndl dlgTmpl;
DialogPtr theDlg;
Handle dHandle;
int dType;
Rect dRect;
int itemHit;
Str255 utilStr;
GrafPtr oldPort;
Boolean validResult = TRUE;
Decimal _decimal_;
double argument;
Boolean read_err;
int index;
dlgTmpl = (DialogTHndl)GetResource('DLOG',6001);
if (dlgTmpl){
/*
center the dialog in the screen rectangle
*/
HNoPurge(dlgTmpl);
centerrect(&(**dlgTmpl).boundsRect,&screen_rect);
/*
get the dialog from the resource fork
*/
theDlg = GetNewDialog(6001,NIL,-1L);
/*
convert the double to a C string, and then to a pascal
string to place in the dialog
*/
double_2_cString(&demo_double[which],FIXEDDECIMAL,6,utilStr);
CtoPstr((char *)utilStr);
/*
set dialog item 4 (the editable text) to the string
converted above, and then select it
*/
GetDItem(theDlg,4,&dType,&dHandle,&dRect);
SetIText(dHandle,utilStr);
SelIText(theDlg,4,0,32000);
ShowWindow(theDlg);
do{ /* until we get a valid double result */
do
ModalDialog(NIL,&itemHit);
while(itemHit > 2);
if (itemHit == OK){
/*
get the resultant string from item 4 of the
dialog
*/
GetDItem(theDlg,4,&dType,&dHandle,&dRect);
GetIText(dHandle,utilStr);
PtoCstr((char *)utilStr);
/*
use SANE to convert it to a decimal record
*/
index = 0;
CStr2Dec(utilStr,&index,&_decimal_,&read_err);
if (read_err){
/*
if no conversion error,
convert the decimal record to a double
*/
fp68k(&_decimal_,&argument,FFEXT|FOD2B);
/*
set the global double to the double
we got from the dialog
*/
demo_double[which] = argument;
/*
force an update of the application window
*/
GetPort(&oldPort);
SetPort(windows[which]);
InvalRect(&windows[which]->portRect);
SetPort(oldPort);
/*
allow us out of dialog
*/
validResult = TRUE;
}
else{
/*
we couldn't convert the resultant string,
so beep and reselect the text.
*/
validResult = FALSE;
SysBeep(1);
SelIText(theDlg,4,0,32000);
}
}
}while(!validResult);
DisposDialog(theDlg);
HPurge(dlgTmpl);
}
}
char *double_2_cString(value, sane_style, dec_digits, result)
double *value;
char sane_style;
int dec_digits;
char *result;
{
DecForm aDecForm;
Decimal aDecimal;
aDecForm.style = sane_style;
aDecForm.digits = dec_digits;
fp68k(&aDecForm, value, &aDecimal, FFEXT+FOB2D);
aDecForm.style = sane_style;
aDecForm.digits = dec_digits;
Dec2Str(aDecForm, &aDecimal,result);
return (PtoCstr(result));
}